package exam.test17;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2020-12-17
 * Time: 8:34
 */
public class Lock {

    protected Owner owner;
    private String masterPassphrase;

    protected boolean lock = false;

    public Lock(Owner owner, String masterPassphrase) {
        this.owner = owner;
        this.masterPassphrase = masterPassphrase;
        this.lock = true;

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Lock lock1 = (Lock) o;
        return lock == lock1.lock &&
                Objects.equals(owner, lock1.owner) &&
                Objects.equals(masterPassphrase, lock1.masterPassphrase);
    }

    @Override
    public int hashCode() {
        return Objects.hash(owner, masterPassphrase, lock);
    }

    public boolean unlock(Owner owner, String masterPassphrase) {
        if (lock) {
            if (this.owner.equals(owner) && this.masterPassphrase.equals(masterPassphrase)) {
                lock = false;
            }
        }
        return lock;
    }


    public boolean isLock() {
        return lock;
    }
}
